// Promise

const baseUrl = 'http://liang.nat200.top/app/index.php?c=entry&a=wxapp&i=2&m=liang_tp_applet&do=api&s='

export const myRequest = (options) => {
	var token = uni.getStorageSync('token');
	
	const {url, method, data, timeout} = options
	
	return new Promise((resolver, reject)=>{
		uni.request({
			url: baseUrl + url,
			method: method || 'GET',
			data: data || {},
			header: {
				token: token
			},
			timeout: timeout || 3000,
			success: res => {
				if (res.statusCode !== 200) {
					return uni.showToast({
						title: '接口请求失败',
						icon: 'none',
						duration: 1000						
					});
				}
				resolver(res)
			},
			fail(err) {
				uni.showToast({
					title: 'fail',
					icon: 'none',
					duration: 1000						
				});
				reject(err)
			}
		})
	})
}